/**
 * 
 */
package com.jquery.ui.tags.javascript.gridColumn;

import com.jquery.ui.core.base.BaseTag;
import com.jquery.ui.core.bean.UIBean;
import com.jquery.ui.core.exception.JqueryUIRuntime;
import com.jquery.ui.dictionary.IPositionEnum;
import com.jquery.ui.tags.beans.script.GridColumnScriptUI;
import com.jquery.ui.tags.javascript.grid.GridTag;

/**
 * @author linyajun
 * 
 * @date	2013-10-10
 * @description   
 */
public class GridColumnTag extends BaseTag {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4979960795079281560L;
	
	private String  clumnName;
	private String headerName;
	private String width;
	private String align="center";
	private boolean sortabl=true;
	
	@Override
	public String getEndTemplate() {
		
		return "gridcolumn-html-end.ftl";
	}

	
	@Override
	public String getStartTemplate() {
		
		return null;
	}

	
	@Override
	public UIBean getUiBean() {
		GridColumnScriptUI column=new GridColumnScriptUI();
		column.setClumnName(clumnName);
		column.setHeaderName(headerName);
		column.setWidth(width);
		column.setAlign(IPositionEnum.parseValue(align));
		column.setSortabl(sortabl);
		GridTag grid=(GridTag)findAncestorWithClass(this, GridTag.class);
		grid.addColNames(headerName);
		return column;
	}
	
	@Override
	protected boolean isValid() {
		GridTag grid=(GridTag)findAncestorWithClass(this, GridTag.class);
		if (grid==null) {
			throw new JqueryUIRuntime("The grid.column tag must be wrapped in Grid Tags! please check!");
		}
		return super.isValid();
	}


	/**
	 * @return the clumnName
	 */
	public String getClumnName() {
		return clumnName;
	}


	/**
	 * @param clumnName the clumnName to set
	 */
	public void setClumnName(String clumnName) {
		this.clumnName = clumnName;
	}


	/**
	 * @return the headerName
	 */
	public String getHeaderName() {
		return headerName;
	}


	/**
	 * @param headerName the headerName to set
	 */
	public void setHeaderName(String headerName) {
		this.headerName = headerName;
	}


	/**
	 * @return the width
	 */
	public String getWidth() {
		return width;
	}


	/**
	 * @param width the width to set
	 */
	public void setWidth(String width) {
		this.width = width;
	}


	/**
	 * @return the align
	 */
	public String getAlign() {
		return align;
	}


	/**
	 * @param align the align to set
	 */
	public void setAlign(String align) {
		this.align = align;
	}


	/**
	 * @return the sortabl
	 */
	public boolean isSortabl() {
		return sortabl;
	}


	/**
	 * @param sortabl the sortabl to set
	 */
	public void setSortabl(boolean sortabl) {
		this.sortabl = sortabl;
	}
	
	

}
